﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FluentNHibernate.Mapping;
using PinCity.Models.Accounts;

namespace PinCity.Models.ORM
{
    /// <summary>
    /// Class, that maps PinCity.Models.Accounts.User
    /// entity with Fluent NHibernate. Any updates to the 
    /// PinCity.Models.Accounts.User should be reflected here.
    /// </summary>
    public class UserMapping : ClassMap<Models.Accounts.User>
    {
        public UserMapping() 
        {
            this.Table("Users");
            this.Id(u => u.ID).GeneratedBy.Native();
            this.Map(u => u.Login);
            this.Map(u => u.Password);
            this.Map(u => u.Email);
            this.Map(u => u.CreationDate);
            this.Map(u => u.LastLoginDate);
            this.Map(u => u.LastActivityDate);
            this.References<Models.Accounts.Role>(u => u.Role);
        }
    }

    /// <summary>
    /// Class, that maps PinCity.Models.Accounts.Role
    /// entity with Fluent NHibernate. Any updates to the 
    /// PinCity.Models.Accounts.Role should be reflected here.
    /// </summary>
    public class RoleMapping : ClassMap<Models.Accounts.Role>
    {
        public RoleMapping()
        {
            this.Table("Roles");
            this.Id(r => r.ID).GeneratedBy.Native();
            this.Map(r => r.Name).Unique();
            this.Map(r => r.LocalizedName);
            this.Map(r => r.Description);
            this.HasMany<User>(r => r.Users).AsBag().Inverse().KeyColumn("Role_id");
        }
    }
}